<template>
  <s-layout title="物流追踪">
    <view>
      <logistics :wlInfo="wlInfo"></logistics>
    </view>
  </s-layout>
</template>

<script setup>
import { ref, onMounted } from "vue";
import logistics from "./xinyu-logistics/xinyu-logistics.vue";
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import sheep from "@/sheep";

const wlInfo = ref({
  delivery_status: 1, // 快递状态 1已签收 2配送中
  post_name: "韵达快递", // 快递名称
  logo: "https://ts4.tc.mm.bing.net/th/id/ODLS.40c9c775-16dc-47f7-98ab-1ea88aa4899b?w=32&h=32&qlt=90&pcl=fffffa&o=6&pid=1.2", // 快递logo
  exp_phone: "95546", // 快递电话
  post_no: "4304678557725", // 快递单号
  addr: "江西省南昌市青云谱区", // 收货地址
  // 物流信息
  list: [],
});

const getExpressdetail = async (id = "defaultOrderSn") => {
  try {
    const { data } = await sheep.$api.order.getOrderMaptrack({
      orderSn: id,
    });
    console.log("data", data.logisticInfoList[0].deliveryCarrier);
    wlInfo.value.post_name = data.logisticInfoList[0].deliveryCarrier;
    wlInfo.value.post_no = data.logisticInfoList[0].deliveryOrderId;
    const reversedTrackInfoList = data.trackInfoList.slice().reverse();

    // 遍历反转后的数组
    reversedTrackInfoList.forEach((item) => {
      const timeArr = item.trackMsgTime.split("T");
      timeArr[1] = timeArr[1].split(".")[0]; // 去掉毫秒部分
      wlInfo.value.list.push({
        timeArr: timeArr,
        context: item.trackContent,
        location: "",
      });
    });
    // wlInfo.value.list = data; // 更新 state
  } catch (error) {
    console.error("Error fetching express list:", error);
  }
};

onLoad((Option) => {
  getExpressdetail(Option.id);
  console.log(Option.address);
  wlInfo.value.addr = Option.address;
});
</script>

<style></style>
<!-- 物流追踪 -->
